# -*- coding: utf-8 -*-
"""
Created on Thu Aug 10 05:47:32 2023

@author: skunk69
"""

import json

chinese_name = u'中国心理咨询与治疗专业人员枯竭量表'
english_name = 'Chinese Burnout Inventory for Professional Staff in Counseling and Psychotherapy'
abbreviation = 'CBI-PSCP'
category = u'应激及相关行为量表'

outline = u"""《中国心理咨询与治疗专业人员枯竭量表》由安芹等于2006年编制。该量表以Maslach枯竭量表-服务行业版（Maslach Burnout Inventory - Human Service Survey）和GBI枯竭量表（Geldard Burnout Inventory）为基础，结合与我国学校、医院或其他机构从业人员访谈结果编制而成。"""

instruction = u"""下面的句子描述您在日常工作中可能出现的一些感受和情形。请仔细阅读，根据自己的实际情况，选择与自己相符合的等级。"""

with open('CBI-PSCP.txt','r',encoding='utf-8') as f:
    lines = f.readlines()
    f.close()

items = {}
for line in lines:
    key,value = line.strip().split('.')
    items[key] = value.strip()

reverse_items = [4,6,10,11,17,20,23,27,28]
scales = [u'情绪压力',u'成就感降低',u'身心疲惫',u'机构支持感降低']
scales_items = [
    [9,13,15,16,19,21,22,25,29,30,31,32],# 情绪压力
    [4,6,7,8,10,11,12,23,24],# 成就感降低
    [1,2,3,5,17,20,26],# 身心疲惫
    [14,18,27,28],# 机构支持感降低    
    ]
# check scales_items
print(f'scale length={[len(l) for l in scales_items]}')

check = []
for l in scales_items:
    check = check+l
print(f'len(check)={len(check)}')

# complementary set
check_set = {i for i in sorted(check)}^{i for i in range(1,33)}
print(f'complementary set= {check_set}')

factors = []
factors_scales = []
rating = [u'完全不同意',u'不同意',u'稍微不同意',u'不知道',u'稍微同意',u'同意',u'完全同意']
score_rules = list(range(1,8))

contents = {
    'instruction':instruction,
    'items':items,
    'reverse_items':reverse_items,
    'scales':scales,
    'scales_items':scales_items,
    'factors':factors,
    'factors_scales':factors_scales,
    'rating':rating,
    'score_rules':score_rules       
    }

implementation = u"""《中国心理咨询与治疗专业人员枯竭量表》属于一个自评量表。"""

reliability = u"""正式样本为175例心理咨询与治疗专业人员。情绪压力、成就感降低、身心疲惫和机构支持感降低4个分量表的内部一致性和重测信度结果比较理想。"""
validity = u"""样本研究表明，量表各条目均具有一定鉴别度。结构效度方面，以样本评定结果的标准分数作为变量进行探索性因素分析。同时实施该量表和Maslach枯竭量表-服务行业版，结果表明，两个量表的总相关系数为0.971，P<0.01。"""
measurements = {'reliability':reliability,'validity':validity}

interpretation = u"""首先将反向题目反向计分，然后将各维度题目相加得到各维度分。所有条目的得分之和即为该量表的总分，反映了我国理咨询与治疗专业人员枯竭的总体状况。"""

applications = u"""无常模。实际应用效果尚待后续研究检验。"""

this_scale = {
    'chinese_name':chinese_name,
    'english_name':english_name,
    'abbreviation':abbreviation,
    'category':category,
    'outline':outline,
    'contents':contents,
    'implementation':implementation,
    'measurements':measurements,
    'interpretation':interpretation,
    'applications':applications    
    }

with open(abbreviation+'.json','w+',encoding='utf-8') as f:
    json.dump(this_scale,f,indent=2,ensure_ascii=False)